<template>
  <div class="join">
    <h1>
      {{ $t("views.index.join.title1") }} <br />
      {{ $t("views.index.join.title2") }}
    </h1>
    <div class="fontBox">
      <div class="selectInput">
        <input class="userName" v-model="userName" type="text"
          :placeholder="$t('views.index.join.from.userName.placeholder')" />
      </div>
      <div class="selectInput">
        <input class="email" v-model="email" type="text" :placeholder="$t('views.index.join.from.email.placeholder')" />
      </div>
      <button @click="joinChange">{{ $t("views.index.join.from.button.title") }}</button>
    </div>

    <div class="tipBox" v-if="tipFlat">
      <img src="@/assets/image/indexImage/pass.png" alt="" />
      <h6>{{ $t("views.index.join.tip.title") }}</h6>
      <button @click="$router.go()">{{ $t("views.index.join.tip.button.title") }}</button>
      <p><span>{{ tipTime }}</span>{{ $t("views.index.join.tip.tipText") }}</p>
    </div>
  </div>
</template>
<script>
import {
  submitJoinUs,
} from '@/api/api';
let int;
export default {
  data() {
    return {
      userName: '',
      email: '',
      tipFlat: false,
      tipTime: 5,
    }
  },
  beforeDestroy() {
    clearInterval(int)
  },
  methods: {
    joinChange() {

      if ((/^\s*$/.test(this.userName))) {
        return alert(this.$t('views.index.join.tip.userName.verification'))
      }

      const emailValidate =
        /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
      if (!emailValidate.test(this.email)) {
        return alert(this.$t('views.index.join.tip.email.verification'))
      }
      submitJoinUs({ name: this.userName, email: this.email }).then(res => {
        if (res.code == 0) {
          this.tipFlat = true;
          int = setInterval(() => {
            if (this.tipTime <= 1) {
              this.$router.go()
            }
            this.tipTime--

          }, 1000);
        } else {
          alert(res.msg)
        }
      })
    }
  },

}
</script>


<style lang="scss" scoped>
.join {
  width: 100%;
  height: 100%;
  background: url("@/assets/image/indexBgImage/indexBgImage_join.jpg") no-repeat;
  background-size: cover;
  overflow-y: scroll;
  box-sizing: border-box;
  padding: 125px 30px;
}

h1 {
  //font-family: HelloFont;
  font-weight: normal;
  font-size: 60px;
  color: #ffffff;
  line-height: 76px;
  margin-top: 244px;
}

.fontBox {
  margin-top: 45px;
  display: flex;
  flex-direction: column;
  justify-content: center;

  .selectInput {
    width: 600px;
    height: 80px;
    border-radius: 4px;
    display: flex;
    box-sizing: border-box;
  }

  input {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    border: 1px solid #ffffff;
    color: #ffffff;
    box-sizing: border-box;
    padding: 30px 40px;
    background: none;
    outline: none;

    //font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 18px;
    color: #ffffff;

    &::placeholder {
      color: #ffffff;
    }

    &.email {
      margin-top: 15px;
    }
  }

  button {
    width: 600px;
    height: 64px;
    margin-top: 50px;
    background: #ffffff;
    border-radius: 4px;
    border: none;
    // font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 24px;
    color: #333333;
  }
}

.tipBox {
  width: 95%;
  margin: 0 auto;
  margin-top: 50%;
  background: #ffffff;
  border-radius: 6px;
  position: absolute;
  left: 50%;
  top: 168px;
  transform: translateX(-50%);
  box-shadow: beige;
  padding: 86px 0 83px;
  display: flex;
  flex-direction: column;
  align-items: center;

  img {
    height: 106px;
  }

  h6 {
    //font-family: HelloFont;
    font-weight: normal;
    font-size: 30px;
    color: #333333;
    line-height: 30px;
    margin: 30px 0 42px;
  }

  button {
    height: 54px;
    background: #d1b87f;
    box-shadow: 0px 2px 21px 0px rgba(152, 112, 65, 0.21);
    border-radius: 6px;
    width: 400px;
    //font-family: Microsoft YaHei;
    font-weight: 400;
    font-size: 16px;
    color: #ffffff;
  }

  p {
    //font-family: Microsoft YaHei;
    font-weight: 400;
    font-size: 14px;
    color: #333333;
    line-height: 14px;
    opacity: 0.5;
    margin-top: 22px;
  }
}
</style>
